package com.zhxy.util.web;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * 组织Url参数的工具类
 * @author 刘勉
 *
 */
public class UrlParameters {
	
	private StringBuilder stringBuilder = new StringBuilder();
	
	private boolean firstAppend = true;
	
	public void appendParameter(String name, Object value) throws UnsupportedEncodingException {
		if (!firstAppend) {
			stringBuilder.append("&");
		} else {
			firstAppend = false;
		}
		stringBuilder.append(URLEncoder.encode(name, "utf-8"));
		stringBuilder.append("=");
		if (value != null)
			stringBuilder.append(URLEncoder.encode(value.toString(), "utf-8"));
	}

	@Override
	public String toString() {
		return stringBuilder.toString();
	}
	
	
}
